<template>
  <el-dialog
    title="优惠券详情"
    :visible.sync="isVisible"
    @close="closeDialog"
    :close-on-click-modal="false"
    :close-on-press-escape="false"
    :modal-append-to-body="false"
    width="65%"
  >
    <el-table :data="formdata">
      <el-table-column property="activityCouponId" label="序号"></el-table-column>
      <el-table-column property="couponName" label="优惠券名称"></el-table-column>
      <el-table-column property="couponType" label="优惠券类型"></el-table-column>
      <el-table-column property="description" label="优惠券条件"></el-table-column>
      <el-table-column property="totalNum" label="优惠券总量"></el-table-column>
      <el-table-column property="takeNum" label="已领取"></el-table-column>
      <el-table-column property="usedNum" label="已使用"></el-table-column>
      <el-table-column property="remainNum" label="剩余总数"></el-table-column>
      <el-table-column label="操作">
        <template slot-scope="scope">
          <el-button v-if="dialogStatus=='已结束'" type="primary" plain size="mini" style="background:#d5d5d5;color:#fff;border:1px solid #d5d5d5">补发</el-button>
          <el-button v-else type="primary" plain size="mini" @click="couponSupply(scope.row)">补发</el-button>
        </template>
      </el-table-column>
    </el-table>
  </el-dialog>
</template>
<script>
import { couponSupply } from "@/api/activityManage";

export default {
  name: "coupondetail",
  inject: ["reload"],
  data() {
    return {
      formdata: this.dialogRow,
      isVisible: this.isShow,
    };
  },
  props: {
    isShow: Boolean,
    dialogRow: Array,
    dialogStatus:String
  },
  methods: {
    closeDialog() {
      this.$emit("closeDialog");
    },
    couponSupply(row) {
      this.$prompt("请输入补发数量", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        inputPattern: /\S/,
        inputErrorMessage: "补发数量不能为空"
      })
        .then(({ value }) => {
          const ele = {
            activityCouponId: row.activityCouponId,
            num: value
          };
          const para = Object.assign({}, ele);
          couponSupply(para)
            .then(res => {
              this.$message({
                type: "success",
                message: "补发成功"
              });
              setTimeout(() => {
                this.reload();
              }, 20);
            })
            .catch(error => {});
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "取消输入"
          });
        });
    }
  }
};
</script>
<style lang="scss" scoped>
.cell {
  .el-button--mini,
  .el-button--mini.is-round {
    padding: 5px 6px !important;
  }
}
</style>